package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.app.util.UserContext;
import cn.wolfcode.trip.base.domain.User;
import cn.wolfcode.trip.base.service.ISystemInformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

@RequestMapping("/systemmessage")
@RestController
public class SystemMessageController {

    @Autowired
    private ISystemInformService systemInformService;


    /**
     * 获取所有的系统通知的信息
     * 参数:
     * 资源：/systemmessage
     * 动作:GET
     */
    @GetMapping
    public Object getSystemMessages(){
        return systemInformService.getList();
    }
    /**
     * 删除指定的系统通知
     * 参数：
     * 资源：/systemmessage/{id}
     * 动作：GET
     */
    @DeleteMapping("/{id}")
    public void delete(@PathVariable Long id,HttpServletResponse resp){
        //获取当前登录的用户
        User currentUser = UserContext.getCurrentUser();
        systemInformService.deleteById(currentUser.getId(),id);
        resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
    }

}
